package org.easyway.tiles;

import java.util.ArrayList;

import org.easyway.collisions.CollisionUtils;
import org.easyway.collisions.SingleCollisionList;
import org.easyway.interfaces.sprites.ISpriteColl;
import org.easyway.lists.BaseList;

public class TiledCollisionList extends SingleCollisionList {

	/**
	 * generated serialVersionUID
	 */
	private static final long serialVersionUID = 7521714433142102538L;

	public TiledCollisionList(boolean toAdd, ISpriteColl spr) {
		super(toAdd, spr);
	}

	public TiledCollisionList(ISpriteColl spr) {
		super(false,spr);
	}

	public void loop() {
		ISpriteColl spr;
		if (isPrecise) {
			ArrayList<ISpriteColl> collList = sprite.getCollisionList();
			for (int i = size() - 1; i >= 0; i--) {
				spr = get(i);
				if (spr == null)
					continue;
				if (CollisionUtils.rectangleHit(sprite, spr))
					if (CollisionUtils.trueHit(sprite, spr)) {
						if (collList != null)
							collList.add(spr);
					}
				// CollisionUtils.hitted(sprite, spr);
			}
		} else {
			ArrayList<ISpriteColl> collList = sprite.getCollisionList();
			for (int i = size() - 1; i >= 0; i--) {
				spr = get(i);
				if (spr == null)
					continue;
				if (CollisionUtils.rectangleHit(sprite, spr)) {
					if (collList != null)
						collList.add(spr);
					// spr.setAddedToCollisionList(true);
				}
			}
		}

	}
	
	/**
	 * sets the list of this object to the object 'list'
	 * 
	 */
	public void setList(BaseList<ISpriteColl> list) {
		super.setList(list);
	}

}
